package com.jsb.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.jsb.common.utils.DateUtils;
import com.jsb.mapper.ExtraWishBuyMapper;
import com.jsb.mapper.WishbuyMapper;
import com.jsb.model.Wishbuy;
import com.jsb.model.WishbuyExample;

@Service
public class WishbuyService{
	
	@Resource
	private WishbuyMapper wishbuyMapper;
	
	@Resource
	private ExtraWishBuyMapper extraWishBuyMapper;
	
	public void addWishbuy(Wishbuy wishbuy) {
		wishbuyMapper.insertSelective(wishbuy);
	}
	
	public void delWishbuyById(String id) {
		wishbuyMapper.deleteByPrimaryKey(id);
	}
	
	public void updateWishbuy(Wishbuy wishbuy) {
		wishbuyMapper.updateByPrimaryKeySelective(wishbuy);
	}
	
	public void updateWishbuyByExample(Wishbuy wishbuy,WishbuyExample wishbuyExample){
	    wishbuyMapper.updateByExampleSelective(wishbuy,wishbuyExample);
	}
	
	public Wishbuy getWishbuyById(String id) {
		return wishbuyMapper.selectByPrimaryKey(id);
	}
	
	public List<Wishbuy> getPageWishbuy(WishbuyExample wishbuyExample) {
		return wishbuyMapper.selectPage(wishbuyExample);
	}
	
	public int countWishbuy(WishbuyExample wishbuyExample) {
		return wishbuyMapper.countByExample(wishbuyExample);
	}
	
	public List<Wishbuy> selectByExample(WishbuyExample example){
	    return wishbuyMapper.selectByExample(example);
	}
	/**
	 * 已购买人次
	 * @param wishbuy
	 * @return
	 */
	public int  sum(Wishbuy wishbuy){
		Integer sum = extraWishBuyMapper.sumWishBuy(wishbuy);
		return sum;
	}

	public long sumLastTime(Wishbuy wishbuy) {
		List<String> list = extraWishBuyMapper.sumLastTime(wishbuy);
		long n = 0;
		for (String str : list) {
//			String formatNumberTime = DateUtils.formatNumberTime(string);
			long time = Long.valueOf(str);
			n += time;
		}
		return n;
	}
}
